<?php
/**
 * Created by PhpStorm.
 * User: Qch
 * Date: 2017/10/13
 * Time: 9:27
 */

namespace Application\Install\Controller;


use J\Intent;
use J\MVC\Controller;
use J\Util\File;

class IndexController extends Controller
{

    protected function optionElementUIIndex(Intent $intent)
    {
        $intent->value = [
            'view'=>[
                'name'=>'Install',
                'url' => '/api.php/Install/Index/Index',
                'admin' => '/element.php/admin/index/index',
                'steps' => [
                    ['name' => 'License', 'title' => '安装协议'],
                    [
                        'title' => '安装完成',
                        'name' => 'Complete',
                        'index' => [
                            'url' => '/',
                            'layer' => 'App',
                        ],
                        'admin' => [
                            'url' => '/element.php/admin/index/index',
                            'layer' => 'App',
                        ],
                    ]
                ],
            ]
        ];
    }

    protected function optionApiIndex(Intent $intent)
    {
        $this->debug('生成配置文件');
        $config =  [
            // 应用密钥
            'application-key' => str_random(),
            'login-session'   => str_random(),
        ];
        // File::add(config_file_name(CONFIG_DIR), $config);
        $this->getApp()->getConfig()->set(null, $config);
        $this->getApp()->getConfig()->save();

        // 虚拟登陆超级管理员
        $this->getApp()->User()->login(['id' => 1]);
        $this->debug('生成.lock文件');
        File::add(RUNTIME_PATH . DS . '.lock', time());
        $intent->ajax(true, '安装完成');
    }

    protected function optionIndex()
    {
        echo '请使用EleAdmin安装';
    }
}